<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/commons/taglibs.jsp" %>
<!DOCTYPE html>
<html>
<%@ include file="/commons/head.jsp" %>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
    <%@ include file="/commons/left.jsp" %>
    <div class="content-wrapper">
        <section class="content-header">
            <h1>
                菜单信息
            </h1>
        </section>
        <div class="content">
            <div class="row">
                <div class="col-md-9">
                    <div class="box box-primary" style="overflow:hidden">
                        <form id="postForm" class="form-horizontal" autocomplete="off">
                            <input type="hidden" name="Id" value="${entity.id}">
                            <div class="box-body" style="padding-top:30px">
                                <div class="form-group">
                                    <label for="inputMenuCode" class="col-sm-2 control-label">菜单编码</label>
                                    <div class="col-sm-5">
                                        <input type="text" class="form-control" autocomplete="off" id="inputMenuCode"
                                               name="menuCode" value="${entity.menuCode}" placeholder="请输入菜单编码">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="inputMenuName" class="col-sm-2 control-label">菜单名称：</label>
                                    <div class="col-sm-5">
                                        <input type="text" class="form-control" autocomplete="off" id="inputMenuName"
                                               name="menuName" value="${entity.menuName}" placeholder="请输入菜单名称">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="selectParentId" class="col-sm-2 control-label">上级菜单名称：</label>
                                    <div class="col-sm-3">
                                        <select class="form-control select2 select2-hidden-accessible" id="selectParentId"
                                                style="width: 100%;" tabindex="-1" aria-hidden="true" name="parentId">
                                            <option value="0">请选择</option>
                                            <c:forEach var="item" items="${parentListMenu}" varStatus="vs">
                                                <option value="${item.id}" <c:if test="${item.id == entity.parentId}">selected="selected"</c:if>>${item.menuName}</option>
                                            </c:forEach>
                                        </select>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="inputMenuHref" class="col-sm-2 control-label">菜单URL：</label>
                                    <div class="col-sm-5">
                                        <input type="text" class="form-control" autocomplete="off" id="inputMenuHref"
                                               name="menuHref" value="${entity.menuHref}" placeholder="请输入菜单URL">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="inputMid" class="col-sm-2 control-label">链接标识：</label>
                                    <div class="col-sm-5">
                                        <input type="text" class="form-control" autocomplete="off" id="inputMid"
                                               name="mid" value="${entity.mid}" placeholder="请输入链接标识"
                                               onkeyup='this.value=this.value.replace(/\D/gi,"")'>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="selectMenuIcon" class="col-sm-2 control-label">图标：</label>
                                    <div class="col-sm-3">
                                        <select class="form-control select2 select2-hidden-accessible" id="selectMenuIcon"
                                                style="width: 100%;" tabindex="-1" aria-hidden="true" name="menuIcon">
                                            <option value="&#xe600;">&#xe600;</option>
                                            <option value="&#xe608;">&#xe608;</option>
                                            <option value="&#xe61b;">&#xe61b;</option>
                                            <option value="&#xe60a;">&#xe60a;</option>
                                            <option value="&#xe61e;">&#xe61e;</option>
                                            <option value="&#xe60e;">&#xe60e;</option>
                                            <option value="&#xe611;">&#xe611;</option>
                                            <option value="&#xe615;">&#xe615;</option>
                                            <option value="&#xe619;">&#xe619;</option>
                                            <option value="&#xe605;">&#xe605;</option>
                                            <option value="&#xe61a;">&#xe61a;</option>
                                            <option value="&#xe614;">&#xe614;</option>
                                            <option value="&#xe61f;">&#xe61f;</option>
                                            <option value="&#xe61d;">&#xe61d;</option>
                                            <option value="&#xe60d;">&#xe60d;</option>
                                            <option value="&#xe613;">&#xe613;</option>
                                            <option value="&#xe618;">&#xe618;</option>
                                            <option value="&#xe606;">&#xe606;</option>
                                            <option value="&#xe604;">&#xe604;</option>
                                            <option value="&#xe617;">&#xe617;</option>
                                            <option value="&#xe602;">&#xe602;</option>
                                            <option value="&#xe60f;">&#xe60f;</option>
                                            <option value="&#xe60c;">&#xe60c;</option>
                                            <option value="&#xe60c;">&#xe60c;</option>
                                            <option value="&#xe603;">&#xe603;</option>
                                            <option value="&#xe61c;">&#xe61c;</option>
                                            <option value="&#xe610;">&#xe610;</option>
                                            <option value="&#xe609;">&#xe609;</option>
                                            <option value="&#xe612;">&#xe612;</option>
                                            <option value="&#xe607;">&#xe607;</option>
                                            <option value="&#xe601;">&#xe601;</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="checkbox" class="col-sm-2 control-label">选项</label>
                                    <div class="col-sm-10">
                                        <div class="checkbox col-sm-1">
                                            <label>
                                                <input type="checkbox" id="checkbox" name="disable" <c:if test="${entity.disable==0}">checked="checked"</c:if>>启用
                                            </label>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="box-footer">
                                <div class="col-sm-2"></div>
                                <button type="button" class="btn btn-info" onclick="submitForm()">提交</button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <%@ include file="/commons/script.jsp" %>
    <script type="text/javascript">
        function submitForm() {
            var id = $('#postForm').find('input[name=Id]').val();
            var url = null;
            if (id == null || id == "") {
                url = "${ctx}/menu/saveMenu?action=add";
            } else {
                url = "${ctx}/menu/saveMenu?action=update";
            }
            var check = $("#postForm").find("input[name='disable']").is(':checked');
            if (check) {
                $("#postForm").find("input[name='disable']").val(0);
            } else {
                $("#postForm").find("input[name='disable']").val(1);
            }
            $.ajax({
                cache: false,
                type: "post",
                url: url,
                data: $('#postForm').serialize(),// formid
                error: function () {
                    alert("系统异常");
                },
                success: function (data) {
                    if (data !== null) {
                        if (data == 0) {
                            //修改失败
                            alert('失败');
                        } else {
                            //添加/修改成功
                            alert('成功');
                            window.location.href="${ctx}/menu/listMenu";
                        }
                    }
                }
            });
        }

        //提交验证
        function checkSubmit(id){
            var menuCode = $("#addMenu input[name='menuCode']").val();
            if(menuCode == null || menuCode == "" || menuCode.trim() == ""){
                massage_info("请填写菜单编码!");
                return false;
            }
            var menuName = $("#addMenu input[name='menuName']").val();
            if(menuName == null || menuName == "" || menuName.trim() == ""){
                massage_info("请填写菜单名称!");
                return false;
            }

            var mid = $("#addMenu input[name='mid']").val();
            if(mid == null || mid == "" || mid.trim() == ""){
                massage_info("请填写连接标识!");
                return false;
            }
            if(!checkMid(id)){
                massage_info("链接标识已存在!");
                return false;
            }

            return true;
        }

        //验证菜单编码
        function checkMid(id){
            //ajax
            var mid = $("#addMenu input[name='mid']").val();
            if(mid == '' || mid == null){
                return true;
            }else{
                var url = contextPath + '/menu/checkMid?' + csrf_name + '='
                    + csrf_value;
                var flag;
                $.ajax({
                    async : false,
                    cache : false,
                    type : "post",
                    url : url,
                    data : {
                        mid : mid,
                        id : id
                    },
                    error : function() {
                        massage_info_fail("系统异常");
                        flag = false;
                    },
                    success : function(data) {
                        if (data == 0) {
                            flag = true;
                        } else {
                            flag = false;
                        }
                    }
                });
                return flag;
            }

        }
    </script>
</body>
</html>
